package org.new9uy.tetris.model;

import java.awt.Color;

import javax.swing.JLabel;

import org.new9uy.tetris.GameConstants;

public class Mino
{
    private int x, y;
    private JLabel label;
    private boolean empty;
    private boolean border;

    public Mino(int x, int y)
    {
        this(x, y, false);
    }

    public Mino(int x, int y, boolean border)
    {
        this.x = x;
        this.y = y;
        this.border = border;
        
        if (border)
        {
            empty = false;
        } else
        {
            empty = true;
        }
        
        label = new JLabel();
        label.setBackground(GameConstants.MINO_EMPTY_COLOR);
        label.setOpaque(true);
        label.setBorder(GameConstants.MINO_BORDER);
        label.setPreferredSize(GameConstants.MINO_PREFERRED_DIMENSION);
    }

    public void setColor(Color color)
    {
        label.setBackground(color);
    }

    public Color getColor()
    {
        return label.getBackground();
    }

    public String coordinates()
    {
        return "(" + x + "," + y + ")";
    }

    public boolean isEmpty()
    {
        return empty;
    }

    public void setEmpty(boolean empty)
    {
        if (border && empty)
        {
            throw new IllegalStateException("Border mino " + coordinates() + " cannot be set to this state.");
        }
        this.empty = empty;
    }

    public boolean isBorder()
    {
        return label.getBackground() == null;
    }

    public JLabel getLabel()
    {
        return label;
    }

    public int getX()
    {
        return x;
    }

    public int getY()
    {
        return y;
    }
}
